/* -----------------------------------------------------------------------
 * Paul Cohen
 * CS 362, Summer 2014
 * Assignment 3
 *
 * cardtest2.c - testing Dominion's Mine card
 * 
 * -----------------------------------------------------------------------
 */

#include "cardtest2.h"
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <string.h>
#include <stdio.h>

int card_test2()
{
	int i = 0;
	int oldSilverCount = 0, newSilverCount = 0;
	int oldGoldCount = 0, newGoldCount = 0;
	int oldDiscardCount = 0;
	int seed = 1000;
	int numPlayers = 2;
	int beforeHandCount = 0;
	int successes = 0;

	int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};

	struct gameState g;
	initializeGame(numPlayers, k, seed, &g);

	printf("\nCard Test 2: Mine\n------------\n");  

	g.hand[0][1] = copper;
	g.hand[0][2] = silver;
	g.hand[0][3] = gold;
	g.hand[0][4] = estate;
	if (cardEffect(mine, 4, 5, 0, &g, 1, 0) != -1)
		printf("Test failed - invalid card accepted as treasure.\n");
	else
		successes++;
	if (cardEffect(mine, 2, -1, 0, &g, 1, 0) != -1)
		printf("Test failed - invalid card number was accepted.\n");
	else
		successes++;
	if (cardEffect(mine, 1, 6, 0, &g, 1, 0) != -1)
		printf("Test failed - card traded for card with too high of a cost.\n");
	else
		successes++;

	for (i = 0; i < g.handCount[0]; i++)
	{
		if (g.hand[0][i] == gold)
			oldGoldCount++;
		else if (g.hand[0][i] == silver)
			oldSilverCount++;
	}
	oldDiscardCount = g.discardCount[0];
	cardEffect(mine, 2, 6, 0, &g, 1, 0);
	for (i = 0; i < g.handCount[0]; i++)
	{
		if (g.hand[0][i] == gold)
			newGoldCount++;
		else if (g.hand[0][i] == silver)
			newSilverCount++;
	}
	if ((newGoldCount == oldGoldCount + 1) && (newSilverCount == oldSilverCount - 1))
		successes++;
	else
		printf("Test failed - cards not traded correctly.\n");

	if (g.discardCount[0] == oldDiscardCount + 2)
		successes++;
	else
		printf("Mine card and/or treasure card not discarded correctly.\n");

	printf("Mine tests completed!\n");
    printf("%d out of 5 tests successful.\n", successes);

	return 0;
}